public class Threadtest5 {
    public static void main(String[] args) throws InterruptedException {
     /*   Thread t1 = new Thread(()->{

            for (int i = 0; i < 3; i++) {
                try {
                    System.out.println(Thread.currentThread().getName()+" is working...");
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();

                }
            }
            System.out.println(Thread.currentThread().getName()+" is ending...");
        },"zhangsan");
        t1.start();

        try {
            t1.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }*/

        Thread t1 =  new Thread(()->{

            for (int i = 0; i < 4; i++) {
                try {
                    System.out.println("这是线程："+Thread.currentThread().getName()+"开始工作了！");
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程"+Thread.currentThread().getName()+"工作完毕！");
        },"zhangsan");
        Thread t2 =  new Thread(()->{

            for (int i = 0; i < 4; i++) {
                try {
                    System.out.println("这是线程："+Thread.currentThread().getName()+"开始工作了！");
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程"+Thread.currentThread().getName()+"工作完毕！");
        },"lisi");
        t1.start();
        t2.start();

    }
}
